<?php


namespace api\modules\v1\controllers\system\base;


use Exception;
use Yii;
use api\controllers\OnAuthController;
use common\helpers\CommonHelper;
use common\models\base\PatientDiseases;
use yii\db\ActiveRecord;

class PatientDiseasesController extends OnAuthController
{
    public $modelClass = PatientDiseases::class;

   //  protected $optional = ['index-patient-diseases', 'update-patient-diseases', 'create-patient-diseases', 'view-patient-diseases', 'delete-patient-diseases','change-status-patient-diseases'];
    protected $optional = [];

    /**
     * v1/system/base/project/index-patient-diseases
     * $page
     * $pageSize
     *
     * @return mixed|ActiveRecord
     */
    public function actionIndexPatientDiseases()
    {
        $params = Yii::$app->request->get();

        return Yii::$app->services->patientDiseases->getList($params);
    }

    /**
     * 获取指定父类下的病种数据
     * v1/system/base/patient-diseases/parent-list
     * $pid
     *
     * @return array
     */
    public function actionParentList()
    {
        $params = Yii::$app->request->get();
        $pid = intval($params['pid'] ?? 0);
        return Yii::$app->services->patientDiseases->getParentList($pid);
    }

    /**
     * v1/system/base/patient-diseases/create-patient-diseases
     * $diseases_name 病种名称
     * $status  1 = 正常  0 = 失效
     *
     * @return mixed|ActiveRecord
     * @throws Exception
     */
    public function actionCreatePatientDiseases()
    {
        $params = Yii::$app->request->post();
        $data = Yii::$app->services->patientDiseases->createDiseases($params);

        return  CommonHelper::api($data['code'],$data['message']);
    }

    /**
     * v1/system/base/patient-diseases/update-diseases
     * $diseases_name 病种名称
     * $status  1 = 正常  0 = 失效
     *
     * @return mixed|ActiveRecord
     * @throws Exception
     */
    public function actionUpdatePatientDiseases()
    {
        $params = Yii::$app->request->post();
        $data = Yii::$app->services->patientDiseases->updateDiseases($params,$params['id']);

        return  CommonHelper::api($data['code'],$data['message']);
    }

    /**
     * v1/system/base/profession/change-status-Profession
     * $id
     * $status  1 = 正常  0 = 失效
     *
     * @return mixed|ActiveRecord
     * @throws Exception
     */
    public function actionChangeStatusPatientDiseases()
    {
        $params = Yii::$app->request->post();
        $status = $params['status'];
        $id = $params['id'];

        return Yii::$app->services->patientDiseases->changeStatus($id,$status);
    }

    /**
     * v1/system/base/profession/delete-patient-diseases
     * $id
     * $status  1 = 正常  0 = 失效
     *
     * @return mixed|ActiveRecord
     * @throws Exception
     */
    public function actionDeletePatientDiseases()
    {
        $id = Yii::$app->request->post('id');

        return Yii::$app->services->patientDiseases->deleteDiseases($id);
    }


    /**
     * v1/system/base/profession/true-delete-patient-diseases
     * $id
     * $status  1 = 正常  0 = 失效
     *
     * @return mixed|ActiveRecord
     * @throws Exception
     */
    public function actionTrueDeletePatientDiseases()
    {
        $id = Yii::$app->request->post('id');

        return Yii::$app->services->patientDiseases->trueDelete($id);
    }



}